charset="UTF-8"
Ext.onReady(function(){
	Ext.QuickTips.init();
     // example of custom renderer function
    function change(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '</span>';
        }
        return val;
    }

    // example of custom renderer function
    function pctChange(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '%</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '%</span>';
        }
        return val;
    }
    
    var hospitalRecord = Ext.data.Record.create([
				{name:'id'},  
              {name:'name'},  
              {name:'admin'},  
              {name:'setupdate',type : 'date', dateFormat : 'm-d-Y' },  
              {name:'introduction'}  
		]);
    // create the data store
    var hospitalStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"queryAllHospitalByPage.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'hospitalVOList'
        	 }, 
        	 hospitalRecord
        	 )
    });
    
    var departmentRecord = Ext.data.Record.create([
				{name:'id'},  
              {name:'name'},  
              {name:'admin'},  
              {name:'setupdate',type : 'date', dateFormat : 'm-d-Y' },  
              {name:'introduction'}  
		]);
    // create the data store
    var departmentStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"queryDepartmentByPage.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'departmentVOList'
        	 }, 
        	 departmentRecord
        	 )
    });
    
    var doctorRecord = Ext.data.Record.create([
				{name:'id'},  
              {name:'username'},
             {name:'name'},
              {name:'sex'},  
              {name:'birthday',type : 'date', dateFormat : 'm-d-Y' },  
              {name:'title'},
              {name:'graduation'},  
              {name:'jobtime',type : 'date', dateFormat : 'm-d-Y'},  
               {name:'introduction'}
		]);
    // create the data store
    var doctorStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"queryDoctorByPage.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'doctorVOList'
        	 }, 
        	 doctorRecord
        	 )
    });

    //查询诊断面板
    var queryDiagnoseForm = new Ext.FormPanel({
        labelAlign: 'top',
        frame:true,
        title: '查询条件',
        bodyStyle:'padding:5px 5px 0',
        width:780,
        collapsible: true,//最小化
        items:[
        	{layout:'column',border:false,labelSeparator:':',
             defaults:{layout: 'form',border:false,columnWidth:.25},
              items:[
                    {items: [{
                    	xtype:"combo",
						name: "hospitalName",
						store:hospitalStore,
						mode:"remote",
						editable:false,
						pageSize: 10,
						displayField:"name",
						hiddenName: "hospitalId",
						valueField:"id",
						triggerAction: 'all',
						fieldLabel:"所属医院",
						emptyText:"请选择医院",
						loadingText:"正在加载数据，请稍后。。。",
						maxLength:20,
                    	maxLengthText:'最大长度20',
                    	allowBlank:false,
                    	blankText:'不能为空'
                    }]},
                    {items: [{
						xtype:"combo",
						name: "departmentName",
						store:departmentStore,
						disabled:true,
						mode:"remote",
						editable:false,
						pageSize: 10,
						displayField:"name",
						hiddenName: "departmentId",
						valueField:"id",
						triggerAction: 'all',
						fieldLabel:"所属科室",
						emptyText:"请选择科室",
						loadingText:"正在加载数据，请稍后。。。",
						maxLength:20,
                    	maxLengthText:'最大长度20',
                    	allowBlank:false,
                    	blankText:'不能为空'
                    }]},
                    {
                    columnWidth:.4,
                    items: [{
						xtype:"combo",
						name: "doctorName",
						store:doctorStore,
						disabled:true,
						mode:"remote",
						editable:false,
						pageSize: 10,
						displayField:"name",
						hiddenName: "doctorId",
						valueField:"id",
						triggerAction: 'all',
						fieldLabel:"医生",
						emptyText:"请选择医生",
						loadingText:"正在加载数据，请稍后。。。",
						maxLength:20,
                    	maxLengthText:'最大长度20',
                    	allowBlank:false,
                    	blankText:'不能为空'
                    }]},
                    {items: [{
                			xtype:'numberfield',
                			allowDecimals:false,
							vtype:'integer',
                    		fieldLabel: '预约编号',
                    		id:'querytreatmentId',
                    		name: 'treatmentId',
                    		anchor:'90%'
                    }]},
                    {items: [{
							xtype:'textfield',
                    		fieldLabel: '患者身份证号码',
                    		id:'querypatientIdentify',
                    		name: 'patientIdentify',
                    		anchor:'90%'
                	}]},
                    {items: [{
							xtype:'textfield',
                    		fieldLabel: '患者姓名',
                    		id:'querypatientName',
                    		name: 'patientName',
                    		anchor:'90%'
                    		}]},
                    {items: [{
							xtype:'datefield',
                    		fieldLabel: '预约日期',
                    		id:'querysignday',
                    		name: 'signday',
                    		emptyText:'请选择日期', 
                    		invalidText : "{0} 是无效的日期 - 必须符合格式： {1}", 
							format : "Y-m-d" , 
                    		anchor:'90%'
                    }]}
               ]}
               ],
		monitorValid:true,
		
        buttons: [{
            text: '查询',
            formBind: true,
            handler:function(){       
            	diagnoseStore.baseParams = {
            		doctorId:queryDiagnoseForm.getForm().findField('doctorId').getValue(),
        			treatmentId:Ext.isEmpty(queryDiagnoseForm.getForm().findField('treatmentId').getValue())?0:queryDiagnoseForm.getForm().findField('treatmentId').getValue(),
                	patientIdentify:queryDiagnoseForm.getForm().findField('patientIdentify').getValue(),
                	patientName:queryDiagnoseForm.getForm().findField('patientName').getValue(),
                	signday:queryDiagnoseForm.getForm().findField('signday').getValue()
        		},
                diagnoseStore.reload({params:{start:0,limit:15}});
                }
        },{
            text: '重置',
            handler:function(){
					queryDiagnoseForm.form.reset();
					queryDiagnoseForm.getForm().findField('doctorId').setDisabled(true);
					queryDiagnoseForm.getForm().findField('departmentId').setDisabled(true);
					diagnoseStore.removeAll();
                }
        }]
    });
    

    
	
  
var diagnoseRecord = Ext.data.Record.create([
				{name:'id'},  
              {name:'patientIdentify'},  
              {name:'patientName'},  
              {name:'doctorName'},
              {name:'doctorTitle'},  
              {name:'departmentName'}, 
              {name:'hospitalName'}, 
              {name:'time'}, 
              {name:'workdate',type : 'date', dateFormat : 'm-d-Y'},
              {name:'descripition'},
               {name:'result'},
               {name:'medecineName'},
               {name:'medecineWay'},
               {name:'medecineOnetime'}
		]);
    // create the data store
    var diagnoseStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"queryDiagnoseByPage.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'diagnoseVOList'
        	 }, 
        	 diagnoseRecord
        	 )
    });

	 var sm = new Ext.grid.CheckboxSelectionModel();  
	 
    var column = new Ext.grid.ColumnModel({
    		columns:[
    		new Ext.grid.RowNumberer(),
    		sm,
            {
            	header: "预约编号", 
            	width: 70, 
            	sortable: true, 
            	dataIndex: 'id'
            },
            {
            	header: "预约日期", 
            	width: 120,
            	sortable: true,
            	renderer: Ext.util.Format.dateRenderer('Y/m/d'), 
            	dataIndex: 'workdate'
            },
            {
            	header: "预约时间", 
            	width: 80,
            	sortable: true,
            	dataIndex: 'time'
            },
            {
            	header: "患者身份证", 
            	width: 150,
            	dataIndex: 'patientIdentify'
            },
            {
            	header: "患者姓名", 
            	width: 100,
            	dataIndex: 'patientName'
            },
            {
            	header: "医院名称", 
            	width: 150,
            	dataIndex: 'hospitalName'
            },
            {
            	header: "科室名称", 
            	width: 100,
            	dataIndex: 'departmentName'
            },
            {
            	header: "医生姓名", 
            	width: 100,
            	dataIndex: 'doctorName'
            },
            {
            	header: "医生职位", 
            	width: 100,
            	dataIndex: 'doctorTitle'
            },
            {
            	header: "病情描述", 
            	width: 100,
            	dataIndex: 'descripition'
            },
            {
            	header: "诊断结果", 
            	width: 100,
            	dataIndex: 'result'
            },
            {
            	header: "药品名称", 
            	width: 100,
            	dataIndex: 'medecineName'
            },
            {
            	header: "给药方式", 
            	width: 100,
            	dataIndex: 'medecineWay'
            },
            {
            	header: "一次用量", 
            	width: 100,
            	dataIndex: 'medecineOnetime'
            }
        ]});
        column.defaultSortable = true;//默认可排序  


        
    // create the Grid
    var diagnoseGrid = new Ext.grid.GridPanel({
        id:'diagnose-grid',
        store: diagnoseStore,
        cm: column,
        sm: sm,
        height:400,
        width:780,
        title:'诊断信息列表',
		loadMask: {msg:'正在加载数据，请稍侯……'},
		collapsible: true,//最小化
        plugins: new Ext.ux.PanelResizer({
            minHeight: 100
        }),
       
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: diagnoseStore,
            displayInfo: true,
			displayMsg:'显示第 {0} 条到 {1} 条记录，一共 {2} 条',  
            emptyMsg:'没有记录',
            plugins: new Ext.ux.ProgressBarPager()
        })
    });
    
    //选中以后激活删除按钮
    diagnoseGrid.getSelectionModel().on('selectionchange', function(sm){    
       	diagnoseGrid.removeBtn.setDisabled(sm.getCount() < 1);
    });
	
    

    queryDiagnoseForm.getForm().findField("hospitalId").on("select",function(){
    	queryDiagnoseForm.getForm().findField('doctorId').setDisabled(true);
    	queryDiagnoseForm.getForm().findField('departmentId').setDisabled(false);
    	departmentStore.baseParams = {
            		hospitalId:queryDiagnoseForm.getForm().findField('hospitalId').getValue()
        		};
        //删除上次查询缓存
        delete queryDiagnoseForm.getForm().findField('departmentId').lastQuery;
        queryDiagnoseForm.getForm().findField('departmentId').reset();
    });
    
    queryDiagnoseForm.getForm().findField("departmentId").on("select",function(){
    	queryDiagnoseForm.getForm().findField('doctorId').setDisabled(false);
    	doctorStore.baseParams = {
            		departmentId:queryDiagnoseForm.getForm().findField('departmentId').getValue()
        		};
        //删除上次查询缓存
        delete queryDiagnoseForm.getForm().findField('doctorId').lastQuery;
        queryDiagnoseForm.getForm().findField('doctorId').reset();
    });
    
   diagnoseGrid.render('diagnoseGrid');
   queryDiagnoseForm.render('queryPanel');
   
   
});